import sql from "@/lib/sql";

// 保存交底书
export async function GET(request) {
  try {
    const name = request.nextUrl.searchParams.get("name");
    const dynasty = request.nextUrl.searchParams.get("dynasty");
    const start_year = request.nextUrl.searchParams.get("start_year");
    const end_year = request.nextUrl.searchParams.get("end_year");

    const result = await sql.getPoets(name, dynasty, start_year, end_year);

    if (result == undefined) {
      return Response.json({
        code: 101,
        status: "fail",
        msg: "获取诗人列表失败",
      });
    } else {
      return Response.json({
        code: 200,
        status: "success",
        msg: result,
      });
    }
  } catch (error) {
    return Response.json({
      code: 9000,
      status: "fail",
      msg: "请求格式错误: " + error,
    });
  }
}
